﻿using System.Collections.Generic;

namespace PflanzenZAOptimierung
{
	class Cause
	{
		Dictionary<string, string> attributes = new Dictionary<string, string>();
		public Dictionary<string, string> Attributes
		{
			get { return attributes; }
			set { attributes = value; }
		}

		Dictionary<string, double> probabilities = new Dictionary<string, double>();
		public Dictionary<string, double> Probabilities
		{
			get { return probabilities; }
			set { probabilities = value; }
		}

		public Cause(string cause)
		{
			string[] cds = cause.Split('#');
			foreach (var cd in cds)
			{
				ParseValues(cd);
			}
		}

		private void ParseValues(string cd)
		{
			string[] tmpName = cd.Split('(');
			string cdName = tmpName[0];
			string[] tmpAtt = tmpName[1].Split(')');
			attributes.Add(cdName, tmpAtt[0]);
			probabilities.Add(cdName, double.Parse(tmpAtt[1].Substring(1, tmpAtt[1].Length - 1)));
		}

		public string ToString(double bucheProb, double birkeProb, double graeserProb, double leerProb)
		{
			string ret = string.Empty;
			ret += "Buche(" + attributes["Buche"] + "):" + bucheProb + "#";
			ret += "Birke(" + attributes["Birke"] + "):" + birkeProb + "#";
			ret += "Gräser(" + attributes["Gräser"] + "):" + graeserProb + "#";
			ret += "Leer(" + attributes["Leer"] + "):" + leerProb;

			return ret;
		}
	}
}
